<template>
	<view class="bg-white">
		<view class="" v-if="is_shows">

			<view v-for="(item,index) in list" :key="index">
				<view class="banmi_sete_view">
					<view class="sete_name">{{item.name}}:</view>
					<template v-if="item.type=='input'">
						<view class="sete_text">{{find[item.fields]}}</view>
						<view class="">
							<button type="primary" size="mini" @click="on_set_key(item.name,item.fields)"
								class="banmi_but">
								设置
							</button>
						</view>
					</template>
					<template v-if="item.type=='select'">
						<view class="sete_text">
							<view @click="on_select(vo.type,item.fields)" v-for="(vo,index1) in item.list">
								<button style="flex-shrink:0; background: transparent;" class="banmi_flex a-c m-l-10">
									<view class="q-y  banmi_flex a-c j-c"
										:class="find[item.fields] == vo.type ? 'key_xz' : 'key_wxz'">
										<text v-if="find[item.fields]== vo.type " class="f-14">✓</text>
									</view>
									<text class="f-14 c_7" style="margin-left: 5px;"
										:class="find[item.fields]== vo.type ? 'key_color' : ''">{{vo.name}}</text>
								</button>
							</view>
						</view>
					</template>

					<template v-if="item.type=='switch'">
						<view class="sete_text">
							{{find[item.fields]==1? item.switch_find.on_name:item.switch_find.off_name }}
						</view>
						<view @click="on_switch(find[item.fields],item.fields)">
							<banmi-switch :is_state="Number(find[item.fields])"></banmi-switch>
						</view>
					</template>
					<template v-if="item.type=='img'">
						<upImg ref="upimg" :field="item.fields" :val='1' name="图片" :list="find[item.fields]|getlist"
							:count="1" t_type="images" @confirm="confirm">
						</upImg>

					</template>



				</view>
			</view>
		</view>

		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-beizhu cancelText="取消" confirmText="确认" lei="0" :name="name" :key="key" @confirm="ajax_set">
			</uni-popup-beizhu>
		</uni-popup>
	</view>
</template>

<script>
	export default {

		data() {
			return {
				find: {},
				name: '',
				key: '',
				list: [{
						name: '网站名称',
						fields: 'name',
						type: 'input'
					},
					{
						name: '备案号',
						fields: 'record_no',
						type: 'input'
					},
					{
						name: '站点描述',
						fields: 'describe',
						type: 'input'
					},

					{
						name: '登录页logo',
						fields: 'login_logo',
						type: 'img'
					},
					{
						name: '系统默认头像',
						fields: 'face',
						type: 'img'
					},
					{
						name: '登陆时效天数(天)',
						fields: 'login_day',
						type: 'input'
					},

					{
						name: '用户注销后几天后能重新注册(天)',
						fields: 'log_off_day',
						type: 'input'
					},
					{
						name: '关闭站点说明',
						fields: 'system_name',
						type: 'input'
					},
					{
						name: '登录状态选项',
						fields: 'login_type',
						type: 'select',
						list: [{
								"type": 1,
								"name": "所有平台只允许1个设备登录",
								"text": ''
							},
							{
								"type": 2,
								"name": "单个平台只允许1个设备登录",
								"text": ''
							}
						]
					},

					{
						name: '主登陆界面',
						fields: 'is_login_set',
						type: 'select',
						list: [{
								"type": 0,
								"name": "微信",
								"text": ''
							},
							{
								"type": 1,
								"name": "账号和短信",
								"text": ''
							}
						]
					},
					{
						name: '注册登陆图形验证码',
						fields: 'reg_img_code',
						type: 'switch',
						switch_find: {
							on_name: '已开启',
							on_val: 1,
							off_name: '已关闭'
						}
					},
					{
						name: '是否开启账号密码注册',
						fields: 'is_account',
						type: 'switch',
						switch_find: {
							on_name: '已开启',
							on_val: 0,
							off_name: '已关闭'
						}
					},
					{
						name: '是否强制绑定手机号',
						fields: 'force_tel',
						type: 'switch',
						switch_find: {
							on_name: '强制',
							on_val: 0,
							off_name: '不强制'
						}
					},
					{
						name: '是否强制设置昵称头像',
						fields: 'force_face',
						type: 'switch',
						switch_find: {
							on_name: '强制',
							on_val: 0,
							off_name: '不强制'
						}
					},
					{
						name: '短信登陆注册是否开启',
						fields: 'is_sms',
						type: 'switch',
						switch_find: {
							on_name: '已开启',
							on_val: 1,
							off_name: '已关闭'
						}
					},
					{
						name: '微信注册登陆是否开启',
						fields: 'is_wechats',
						type: 'switch',
						switch_find: {
							on_name: '已开启',
							on_val: 1,
							off_name: '已关闭'
						}
					},
					{
						name: '关闭站点',
						fields: 'system',
						type: 'switch',
						switch_find: {
							on_name: ' 运行中',
							on_val: 1,
							off_name: '已关闭'
						}
					},
				],
				is_shows: false
			}
		},
		onLoad() {
			this.init();
		},
		methods: {
			async init() {
				const ret = await this.Banmikeji.index_index({});
				this.find = ret.data;
				this.is_shows = true

			},
			confirm(list, img_url, field, val, name) {
				if (list.length > 0) {
					this.find[field] = list[0]['attachment'];
					this.key = field;
					this.ajax_set(list[0]['attachment']);
				} else {
					this.find[field] = '';
				}

			},
			on_set_key(name, key) {

				this.name = name;
				this.key = key;
				this.$refs.alertDialog.open()
			},
			on_select(val, key) {
				this.key = key;
				this.ajax_set(val);
			},
			change(index) {
				return index ^ 1;
			},
			on_switch(index, name) {
				var that = this;
				var val = this.change(index)
				that.key = name;
				that.ajax_set(val);
			},
			async ajax_set(val) {
				var that = this;
				that.requestParams = {};
				that.requestParams[that.key] = val
				that.requestParams['key'] = that.key

				if (that.key == 'name') {
					uni.setStorageSync('admin_title', val);
				}


				const ret = await this.Banmikeji.Settings_set_key_sets(that.requestParams);
				uni.showToast({
					title: ret.msg,
					icon: 'none'
				})
				if (ret.status == 200) {
					this.find[that.key] = val;
					this.$refs.alertDialog.close()
				}


			},

		}
	}
</script>

<style>
	button {
		padding: 0;
	}

	button::after {
		border: none;
	}
</style>